﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Camelio.BLL;

namespace Camelio
{
    public partial class AuthenticationForm : Form
    {
        public AuthenticationForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Admin adm = new Admin();
            adm.Where.AminUserName.Value = txtBoxUserName.Text;
            adm.Where.AminUserName.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
            adm.Where.AminUserName.Conjuction = MyGeneration.dOOdads.WhereParameter.Conj.And;
            adm.Where.AdminPassword.Value = txtBoxPassword.Text;
            adm.Where.AdminPassword.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
            adm.Query.Load();

            if (adm.RowCount>0)
            {
                Camelio.Properties.Settings.Default.LoginType = "admin";
                Camelio.Properties.Settings.Default.Save();
                Application.Restart();
                //Program.userName = txtBoxUserName.Text;
                //Program.loginType = adm.AdminType;
                //MainForm mf = new MainForm();
                ////SettingsForm mf = new SettingsForm();
                //mf.Show();
                //mf.FormClosing += mf_FormClosing;
                //this.Hide();
            }
            else
            {
                MessageBox.Show("اسم المستخم او كلمة المرور غير صحيحة", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        void mf_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Close();
        }

        private void AuthenticationForm_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void txtBoxPassword_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                button1_Click(new object(), e);
            }
        }

        private void txtBoxUserName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtBoxPassword.Focus();
            }

        }

        private void AuthenticationForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }
    }
}
